package com.crm.service.system.role.controller;


import com.crm.model.common.dtos.ResponseResult;
import com.crm.model.system.role.dto.RoleDto;
import com.crm.model.system.role.dto.RolePageDto;
import com.crm.model.system.role.pojo.Role;
import com.crm.service.system.role.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/role")
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/add")
    public ResponseResult add(@RequestBody RoleDto roleDto){
        log.info(roleDto.toString());
        ResponseResult save = roleService.save(roleDto);
        return save;
    }

    @GetMapping("/getById/{id}")
    public ResponseResult getById(@PathVariable Integer id){
        ResponseResult byId = roleService.getById(id);
        return byId;
    }

    @DeleteMapping("/delete/{ids}")
    public ResponseResult deleteById(@PathVariable List<Integer> ids){
        log.info(ids.toString());
        ResponseResult responseResult = roleService.deleteByIds(ids);
        return responseResult;
    }

    @PostMapping("/search")
    public ResponseResult getAll(@RequestBody RolePageDto rolePageDto){
        ResponseResult all = roleService.getAll(rolePageDto);
        return all;
    }

}
